package org.example.likou150.array;
/*
* https://leetcode.cn/problems/remove-duplicates-from-sorted-array-ii/?envType=study-plan-v2&envId=top-interview-150
* */
public class RemoveDuplicates2 {
    public static void main(String[] args) {
        int[] nums = new int[]{0,0,1,1,1,1,2,3,3};
        RemoveDuplicates2 removeDuplicates2=new RemoveDuplicates2();
        int current = removeDuplicates2.removeDuplicates(nums);
        System.out.println(current);
    }

    public int removeDuplicates(int[] nums) {
        int current=0;
        int count=1;
        for(int i=1; i<nums.length; i++){
            if(count<2 && nums[i]==nums[current]){
                count++;
                nums[++current]=nums[i];
                continue;
            }
            if(nums[i]!=nums[current]){
                nums[++current]=nums[i];
                count=1;
            }
        }
        return current+1;
    }
}
